package com.zut.dao;

import com.zut.domain.Recruitment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RecruitmentDao {

    @Results(id = "groupWithRecruitment",
            value = {
                    @Result(property = "id", column = "recruitment_id", id = true),
                    @Result(property = "img", column = "recruitment_img", id = true),
                    @Result(property = "background", column = "recruitment_background"),
                    @Result(property = "culture", column = "recruitment_culture"),
                    @Result(property = "advertisement", column = "recruitment_advertisement"),
            })
    @Select("select * from recruitment")
    List<Recruitment> getAll();

    @Insert("insert into recruitment (recruitment_id,recruitment_img,recruitment_background," +
            "recruitment_culture,recruitment_advertisement) " +
            "values(#{id},#{img},#{background},#{culture},#{advertisement})")
    int insert(Recruitment recruitment);

    @Delete("delete from recruitment where recruitment_id = #{id}")
    int deleteById(String id);

    @Update("<script>                                                                               "
            + "update recruitment                                                                   "
            + "<set>                                                                                "
            + "  <if test='img != null'> recruitment_img=#{img},                               </if>"
            + "  <if test='background != null'> recruitment_background=#{background},          </if>"
            + "  <if test='culture != null'> recruitment_culture=#{culture},                   </if>"
            + "  <if test='advertisement != null'> recruitment_advertisement=#{advertisement}, </if>"
            + "</set>                                                                               "
            + "where recruitment_id = #{id}                                                         "
            + "</script>                                                                            ")
    int update(Recruitment recruitment);
}
